<%@ page import="News.service.UserServer" %>
<%@ page import="java.util.List" %>
<%@ page import="News.entity.User" %>
<%@ page import="javax.swing.*" %>
<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2021/11/29 0029
  Time: 16:15
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>control</title>
</head>
<body>
<%
    String type=(String)request.getSession().getAttribute("type");
    UserServer l=new UserServer();

    String username=request.getParameter("username");
    String pwd=request.getParameter("pwd");
    Integer i=null;
    if("登录".equals(type)){
        i=l.selectUser(username,pwd);

        if(i==null){
            response.sendRedirect("Login.jsp");
            JOptionPane.showMessageDialog(null,"用户名或密码错误");
        }else if(i==0){
            Cookie cookie=new Cookie("isControl","0");
            cookie.setMaxAge(60);
            response.addCookie(cookie);
            response.sendRedirect("Index.jsp");
        }else if(i==1){
            Cookie cookie=new Cookie("isControl","1");
            cookie.setMaxAge(60);
            response.addCookie(cookie);
            response.sendRedirect("cUser.jsp");
        }
    }else if("注册".equals(type)){
        i=l.selectUserName(username);
        if(i>0){
            response.sendRedirect("Register.jsp");
            JOptionPane.showMessageDialog(null,"用户名已注册");
        }else if(i==0){
            int cont=Integer.parseInt(request.getParameter("isControl"));
            i=l.Register(username,pwd,cont);
            if(i>0){
                response.sendRedirect("Login.jsp");
                JOptionPane.showMessageDialog(null,"注册成功");
            }else{
                response.sendRedirect("Register.jsp");
                JOptionPane.showMessageDialog(null,"注册失败");
            }
        }
    }else{
        JOptionPane.showMessageDialog(null,"地址错误");
        response.sendRedirect("Login.jsp");
    }
%>
</body>
</html>
